package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.ShareDAO;


/**
 * Servlet implementation class DeleteShare
 */
@WebServlet("/DeleteShare")
public class DeleteShare extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	public static final String VUE = "/WEB-INF/sentShare.jsp";
	public static final String VUE_INDEX = "/WEB-INF/connectionUser.jsp";
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteShare() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		/* Récupération de la session depuis la requête */
	    HttpSession session = request.getSession();
	    
	    if(session.getAttribute("user")!=null){
		
	    	//on recuperere l'identifiant de l'utilisateur
			int idSender = Integer.parseInt(request.getParameter("idSender"));
			int idShareOnPhone= Integer.parseInt(request.getParameter("idShareOnPhone"));
			
			ShareDAO sDAO=new ShareDAO();
			sDAO.deleteShare(idShareOnPhone, idSender);
	    	
	    	this.getServletContext().getRequestDispatcher(VUE).forward(request, response);
	    }else{
	    	this.getServletContext().getRequestDispatcher(VUE_INDEX).forward(request, response);
	    }
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
